from transitions import Machine


class Matter(Machine):
    states = ['init', 'segment', 'text', 'question', 'option']
    transitions = [
        {'trigger': 'start_segment', 'source': 'init', 'dest': 'segment', 'conditions': 'is_segment'},
        {'trigger': 'start_question', 'source': 'init', 'dest': 'question', 'conditions': 'is_question'},
        {'trigger': 'start_option', 'source': 'init', 'dest': 'option', 'conditions': 'is_option'},
        {'trigger': 'start_text', 'source': 'init', 'dest': 'text', 'conditions': 'is_text'}
    ]

    def is_question(self):
        print('is_question')
        if self.token['type'] == 'question':
            return True
        return False

    def is_segment(self):
        print('is_segment')
        if self.token['type'] == 'segment':
            return True
        return False

    def is_option(self):
        print('is_option')
        if self.token['type'] == 'option':
            return True
        return False

    def is_text(self):
        print('is_text')
        if self.token['type'] == 'text':
            return True
        return False

    def on_exit_segment(self):
        print('on_exit_segment ' + self.state + ' state!')
        self._push_blocks(_token)
    def on_enter_segment(self):
        print('on_enter_segment ' + self.state + ' state!')
    def __init__(self):
        self.status = 'init'
        Machine.__init__(self, states=self.states, transitions=self.transitions, initial='init')
        # self.add_transition(trigger='melt', source='solid', dest='liquid')


lump = Matter()
print(lump.state)
# solid
# liquid
for i in [{"type": 'segment'},{ "type": 'question',}, {"type": 'text'}, {"type": 'text'}]:
    lump.token = i
    lump.to_init()
    # if lump.state == 'segment':
    if lump.start_segment():
        pass
    elif lump.start_question():
        pass
    elif lump.start_option():
        pass
    elif lump.start_text():
        pass
    print(lump.state)
